﻿using SharpGeo.Indexing;
using SharpGeo.IO.ShapeFile;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SharpGeo.Console
{
    //TODO clean up the load layers to 
    // c) check to see if the exterior ring contains the interior ring


    class Program
    {
        static void Main(string[] args)
        {
            //var layers = ShapeFile.LoadLayers(
            //    new Uri(@"file:\\C:\Users\Steven\Documents\Coding\GIS Data\10m_physical\ne_10m_land_scale_rank.shp"),
            //    new Uri(@"file:\\C:\Users\Steven\Documents\Coding\GIS Data\10m_physical\ne_10m_land_scale_rank.dbf"),
            //    new Uri(@"file:\\C:\Users\Steven\Documents\Coding\GIS Data\10m_physical\ne_10m_land_scale_rank.prj"),
            //    (a, b) => {
            //        return a.Attributes["scalerank"] == b.Attributes["scalerank"];                
            //    });

            //foreach(var layer in layers)
            //{
            //    layer.MinimumScale = 0;
            //    layer.MaximumScale = StandardScales.GetScale(int.Parse(layer.Attributes["scalerank"]));
            //}

            //save layers

            TestBulkLoad();
        }

        public const int MaximumPoints = 150;
        public const int NumberOfShapes = 10000;

        public static void TestBulkLoad()
        {
            var random = new Random();
            for (int k = 0; k < 10; k++)
            {
                var shapes = new List<PolyShape>(NumberOfShapes);
                for (int i = 0; i < NumberOfShapes; i++)
                {
                    var numberOfPoints = random.Next(0, MaximumPoints);
                    var points = new double[numberOfPoints * 2];

                    for (int j = 0, index = 0; j < numberOfPoints; j++, index += 2)
                    {
                        points[index] = (random.NextDouble() * 360) - 180;
                        points[index + 1] = (random.NextDouble() * 180) - 90;
                    }

                    shapes.Add(new PolyShape(new LinearRing(points, 2), null, GeometryType.Polygon));
                }
                var tree = new ReadOnlyRTree<PolyShape>(shapes);
                System.Console.Write(".");
            }
        }
    }
}